﻿using System;
using System.Text;

// Write a program that converts a string to a sequence of C# Unicode character literals. Use format strings.

namespace UnicodeChars
{
    class UnicodeChars
    {
        static char GetSymbol(int number)
        {
            if (number > 9)
            {
                return (char)(55 + number); // 55 + 10 = 65 in ASCII = 'A'
            }

            return (char)(number + '0');
        }

        static string ConvertDecimalToHexadecimal(int number)
        {
            StringBuilder result = new StringBuilder();

            for (int num = number; num > 0; num /= 16)
            {
                result.Insert(0, GetSymbol(num % 16));
            }

            return result.ToString();
        }

        static string StringToUnicode(string text)
        {
            StringBuilder result = new StringBuilder();

            foreach (char ch in text)
            {
                result.Append("\\u").Append(ConvertDecimalToHexadecimal((int)ch).PadLeft(4, '0'));
            }

            return result.ToString();
        }

        static void Main()
        {
            Console.WriteLine(StringToUnicode("Hi!"));
        }
    }
}
